package com.springboot.study.service;

import org.springframework.core.type.ClassMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @Author: guodong
 * @Date: 2021/10/9 9:57
 * @Version: 1.0
 * @Description:
 */
@Component
public class TestTypeFilter implements TypeFilter {

    @Override
    public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {
        //获取当前类的class的源信息
        ClassMetadata classMetadata = metadataReader.getClassMetadata();
        //类名称中包含Dao就可以被扫描到
        if(classMetadata.getClassName().contains("Controller")) {
            System.out.println("classMetadata.getClassName():"+ classMetadata.getClassName());
            return true;
        }
        return false;
    }


}

